package platform

import "reflect"

// Entry is the interface that all entry types must implement.
type Entry interface {
	SetInstruction(instruction string)
	SetInput(input string)
	SetOutput(output string)
}

// EntryType is the interface that all entry types must implement.
type EntryType interface {
	// Validate returns an error if the entry is invalid.
	Validate() error
}

// entryTypes is the list of registered entry types.
var entryTypes = make(map[string]reflect.Type)

func RegisterEntryType(name string, entry Entry) {
	entryTypes[name] = reflect.TypeOf(entry).Elem()
}

func NewEntry(name string) Entry {
	// Create a new value of the correct type, and return it
	return reflect.New(entryTypes[name]).Interface().(Entry)
}
